/**
 * Created by Administrator on 2017/5/25.
 */
'use strict'

var evaluteTemplete = require('html!./model-evaluate.html');
require('./model.less');
module.exports = {
  template: evaluteTemplete,
  data:function(){
    return {
      comment:'',
      modelId:'00',
      modelName:'',
      starLevel:'5',
      modelPhoto:'http://localhost:8080/1.png'
    }
  },
  created:function(){
    /*this.modelId = this.$route.query.modelId;
    this.modelName = this.$route.query.modelName;
    this.modelName = this.$route.query.modelPhoto;*/
    if(this.$route.query.modelId!=null && this.$route.query.modelId!=""){
      this.modelId = this.$route.query.modelId;
    }
    if(this.$route.query.modelName!=null && this.$route.query.modelName!=""){
      this.modelName = this.$route.query.modelName;
    }
  },
  mounted:function(){
    this.mouse();
  },
/*  beforeRouteEnter:function(to, from, next){
    if(!localStorage.getItem("userId")){
      layer.confirm('请先登陆', {
        btn: ['确定'] //按钮
      }, function(index){
        layer.close(index);
        next({ path: '/login' })
      });
    }else{
      next();
    }
  },*/
  methods:{
    evaluate:function(){
      var me = this;
      if(me.comment ==''){
        layer.msg('评论不能为空');
        return;
      };
      if(me.comment.length>200){
        layer.msg('评论不能超过200字');
        return;
      }
      this.$http.get('/eyeCommentController/addComment.do?modelId='+me.modelId+'&score='+me.starLevel+'&content='+me.comment).then(function(res) {
        //获取模型详情
        console.log('添加评论，请求后返回结果: ', res);
        if(res.data.status === 'OK') {
          layer.msg(res.data.result);
          me.$router.go(-1);
        }else {
          layer.msg(res.data.result);
        }
      });
    },
    confir:function(){
      this.$router.go(-1);
    },
    mouse:function(){
      var me = this;
      $('#evlStar li').mousemove(function () {
        var $starNum = $(this).index()-10;
        var $starPo = 'right ' + ($starNum*18)+'px';
        var $evalScore = $starNum*.5+5;
        $(this).parent().css('background-position',$starPo);
        me.starLevel = $evalScore;
        $('#evalScroe').text($evalScore);
      })
    }
  }
};
